package com.xishu.task;

import com.xishu.dao.jpa.CustomerTicketDao;
import com.xishu.service.CommonService;
import com.xishu.util.Tools;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Api(description = "处理会员过期的优惠券")
@Component
public class CustomerTicketExpiredTask implements Tools {
    private static Logger logger = LoggerFactory.getLogger(CustomerTicketExpiredTask.class);
    private CommonService commonService = CommonService.getInstance();

    @Autowired
    private CustomerTicketDao customerTicketDao;

    /**
     * 凌晨一点执行
     */
    @Scheduled(cron = "0 0 0 * * ?")
//    @Scheduled(cron = "0/30 18 13 * * ?")
    public void scanTicket() {
        long currentTimeMillis = System.currentTimeMillis();
        logger.info("start to ticket to expire , time is {}", currentTimeMillis);
        customerTicketDao.expireTicket(currentTimeMillis);
        logger.info("end to ticket to expire , time is {}", currentTimeMillis);
    }
}
